package com.example.jussi.listviewdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Weathy> weathyList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initWeathy();
        WeathyAdapter adapter = new WeathyAdapter(MainActivity.this, R.layout.weathy_item, weathyList);
        ListView listView = (ListView) findViewById(R.id.list_view);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                Weathy weathy = weathyList.get(position);
                Toast.makeText(MainActivity.this, weathy.getName(), Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initWeathy() {
        Weathy sunny = new Weathy("Sunny", R.drawable.weathy_01);
        weathyList.add(sunny);
        Weathy cloud = new Weathy("Cloud", R.drawable.weathy_02);
        weathyList.add(cloud);
        Weathy smallRain = new Weathy("SmallRain", R.drawable.weathy_07);
        weathyList.add(smallRain);
        Weathy minRain = new Weathy("MidRain", R.drawable.weathy_08);
        weathyList.add(minRain);
        Weathy bigRain = new Weathy("BigRain", R.drawable.weathy_09);
        weathyList.add(bigRain);
        Weathy thunderstorm = new Weathy("Thunderstorm", R.drawable.weathy_10);
        weathyList.add(thunderstorm);
        Weathy smallSnow = new Weathy("SmallSnow", R.drawable.weathy_11);
        weathyList.add(smallSnow);
        Weathy midSnow = new Weathy("MidSnow", R.drawable.weathy_12);
        weathyList.add(midSnow);
        Weathy bigSnow = new Weathy("BigSnow", R.drawable.weathy_13);
        weathyList.add(bigSnow);
        Weathy icePao = new Weathy("IcePao", R.drawable.weathy_14);
        weathyList.add(icePao);
    }
}
